namespace Antivirus.Domain.Digest
{
    using System;

    public abstract class Hash
    {
        protected Hash(byte[] content)
        {
            Content = content;
        }

        public byte[] Content { get; private set; }

        public int Length
        {
            get { return Content.Length; }
        }

        public override string ToString()
        {
            return BitConverter.ToString(Content).Replace("-", string.Empty);
        }

        public bool Equals(Hash other)
        {
            if (Length != other.Length)
                return false;

            for (var i = 0; i < Length; i++)
                if (Content[i] != other.Content[i])
                    return false;

            return true;
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj))
                return false;
            if (ReferenceEquals(this, obj))
                return true;
            if (obj.GetType() != GetType())
                return false;

            return Equals((Hash) obj);
        }

        public override int GetHashCode()
        {
            return Content.GetHashCode();
        }
    }
}